package com.qzl.feiq.strategy.impl;

import com.qzl.feiq.annotation.ReceiveType;
import com.qzl.feiq.config.FeiQCache;
import com.qzl.feiq.enu.MessageTypeEnum;
import com.qzl.feiq.enu.UserActionTypeEnum;
import com.qzl.feiq.message.Message;
import com.qzl.feiq.strategy.Receive;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import com.qzl.feiq.config.StaticConfig;

/**
 * 上线的广播消息回复
 */
@Slf4j
@ReceiveType(command = 6291457)
public class IpmsgBrEntryImpl implements Receive {
    /**
     * 回复消息
     *
     * @param channel
     */
    @Override
    public void receiveMsg(Channel channel, Message oldMessage) {
        log.info("用户{}上线", oldMessage);
        Message message = new Message(oldMessage.getFromUserIp(), MessageTypeEnum.broadcast, StaticConfig.IPMSG_ANSENTRY);
        channel.writeAndFlush(message);
        FeiQCache.onlineUsers.put(oldMessage.getFromUserIp(), oldMessage.getSenderHost());
        FeiQCache.userQueue.add(UserActionTypeEnum.login);
    }
}
